<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>设备类型</title>
	<th:block layout:fragment="head-include">
	</th:block>
 <script type="text/javascript">
 var checkboxs=document.getElementsByName("chk");
 var all=document.getElementById("all");
 var cklen=checkboxs.length;
 all.onclick=function()
 {
	 if(this.checked==true)
	 {
	   for(var i=0;i<cklen;i++)
	   {
	     checkboxs[i].checked=true;
	   }
	 }
	 else
	 {
	   for(var i=0;i<cklen;i++)
	   {
	     checkboxs[i].checked=false;
	   }
	 }
 }

 </script> 
 <script th:inline="javascript">
	var orgdevs = [[${orgdevs}]].length;
	var devicecount = document.getElementsByName("count");
	for(var i=0;i<devicecount.length;i++){
		devicecount[i].innerHTML = Number(devicecount[i].innerHTML)+Number(orgdevs);
	}
</script>
<script th:inline="javascript">
 
 $("#popButton").click(function() {
	 var orgid = [[${orgid}]];
	 var checkboxs=document.getElementsByName("chk"); 
	 var arr=[];
	 for(var i=0;i<checkboxs.length;i++){
		 if(checkboxs[i].checked===true){
			 if(i<orgdevs){
				 arr.push([[${orgdevs}]][i].device.id);
			 }
			 else{
				 arr.push([[${devices}]][i-orgdevs].id);
			 }
		 }
	 }
	 window.winTip.alert("保存成功");
	 $.ajax({
			url: "orgdev/modify",
			type: 'POST',
			dataType: 'html',
			data: {"orgid":orgid,arr:arr},
			traditional:true,
			success: function (result) {
				orgDevList ();
			},
			error: function (error) {
				alert(error);
			}
		});		
	})
	
	
	
	
// 	$("#btn_find").click(function() {
// 	debugger;
// 	 var orgid = [[${orgid}]];
// 	 var address = document.getElementById("address").value;
// 	 $.ajax({
// 			url: "/orgdev/list/"+orgid,
// 			type: 'POST',
// 			dataType: 'html',
// 			data: {"address":address},
// 			success: function (result) {
				
// 				$("tbody").html("");
// 				 $("tbody").append();
// 	          },
// 			error: function (error) {
// 				alert(error);
// 			}
// 		});				
// 	})
 </script>


<script th:inline="javascript">
	function orgDetail() {
	   		$.ajax({
		         url: "/organization/edit/id/"+orgid,
		         type: 'POST',
		         dataType: 'html',
		         success: function(data) {
	 				$("#orgList").html(data);
	          	},
				error: function (error) {
					alert(error);
				}
	       	});
	}
</script>	
	
</head>
<body>
<section class="content-header">
	      <row>
	         <ol class="breadcrumb">
		        <li><a href="#"><i class="fa fa-home"></i> 首页</a></li>
		        <li class="active"><i class="fa  fa-map-marker"></i>组织管理</li>
		      </ol>
	      </row>    
</section>
<section layout:fragment="content" class="content">
<div class="row">
    <div class="col-md-12 ">
        <div class="box box-primary">
            <div class="box-header with-border">
				<a href="javascript:orgDetail();"><i class="fa fa-map-marker"></i> 编辑组织</a></li>&nbsp;&nbsp;&nbsp;
                <h3 class="box-title">挂靠设备</h3>
<!-- 				<input type="text" id="address"/> -->
<!-- 				<button type="button" class="btn btn-primary btn-sm" id="btn_find" >查找</button> -->
            </div>
            
		  <div class="box-header with-border">
            <h3 class="box-title">组织下设备列表</h3>
            <div class="box-tools">
              <button type="button" class="btn btn-primary btn-sm" id="popButton">&nbsp;&nbsp;确定</button>
            </div>
          </div>
          
    
          
          <div class="box-body no-padding">
            <table class="table table-striped table-bordered table-hover dataTable">
              <thead>
                <tr class="bg-light-blue disabled">
                  <th>
                  <input type="checkbox" id="all">
                  </th>
                  <th>
                    序号
                  </th>
                  <th>
                    设备编号
                  </th>
                  <th>
                    设备类型
                  </th>
                  <th>
                    使用状态
                  </th>
                  <th>
                    设备名称
                  </th>
                  <th>
                    安装地址
                  </th>
                  <th>
                    安装日期
                  </th>
                  <th>
                    经度
                  </th>
                  <th>
                    纬度
                  </th>
                  <th>
                    保养日期
                  </th>
                  <th>
                    联系人
                  </th>
                  <th>
                    联系人电话
                  </th>
                  <th>
                    备注
                  </th>
                </tr>
              </thead>
              <tbody>
                <tr th:each="orgdev,iterStat : ${orgdevs}">
                  <td><input type="checkbox" checked="checked" name="chk"></td>
                  <td th:text="${iterStat.count}">0</td>
                  <td th:text="${orgdev.device.devCode}"></td>
                  <td th:text="${orgdev.device.deviceType}?${orgdev.device.deviceType.deviceTypeName}:''"></td>
                  <td th:text="${orgdev.device.usestatus}==1?'正常使用':'停用'">使用情况</td>
                  <td th:text="${orgdev.device.deviceName}"></td>
                  <td th:text="${orgdev.device.address}"></td>
                  <td th:text="${orgdev.device.installationDate}"></td>
                  <td th:text="${orgdev.device.latitude}"></td>
                  <td th:text="${orgdev.device.longitude}"></td>
                  <td th:text="${orgdev.device.maintenanceDate}"></td>
                  <td th:text="${orgdev.device.linkMain1}"></td>
                  <td th:text="${orgdev.device.linkPhone1}"></td>
                  <td th:text="${orgdev.device.remark}"></td>
                </tr>
                <tr th:each="device,iterStat : ${devices}">
                  <!-- <td class="text-center"  th:text="${iterStat.count}">0</td>	 -->
                  <td><input type="checkbox" name="chk"></td>
                  <td name="count" th:text="${iterStat.count}"></td>
                  <td th:text="${device.devCode}"></td>
                  <td th:text="${device.deviceType}?${device.deviceType.deviceTypeName}:''"></td>
                  <td th:text="${device.usestatus}==1?'正常使用':'停用'">使用情况</td>
                  <td th:text="${device.deviceName}"></td>
                  <td th:text="${device.address}"></td>
                  <td th:text="${device.installationDate}"></td>
                  <td th:text="${device.latitude}"></td>
                  <td th:text="${device.longitude}"></td>
                  <td th:text="${device.maintenanceDate}"></td>
                  <td th:text="${device.linkMain1}"></td>
                  <td th:text="${device.linkPhone1}"></td>
                  <td th:text="${device.remark}"></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
 
   </section>
</body>
</html>